import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

# 设置中文字体和关闭工具栏
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False

image = cv2.imread('./img/flowers.jpg')

array = np.random.randint(0, 256, size=image.shape, dtype=image.dtype)

new_image = cv2.subtract(image, array)

plt.figure(figsize=(12, 6))

plt.subplot(1, 2, 1)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title('原图')
plt.axis('off')

plt.subplot(1, 2, 2)
plt.imshow(cv2.cvtColor(new_image, cv2.COLOR_BGR2RGB))
plt.title('新图')
plt.axis('off')

plt.show()
